Class Concert
- java.lang.Object
-
- MusicLandscape.entities.Event
-
- MusicLandscape.entities.Concert
-
public class Concert extends Event
Represents a concert of a certain artist with a certain set list as a specific event.As an extension of a generic event a concert provides the possibility to store the setlist. The setlist is the sequence of non-null tracks played at a concert. Class concert provides methods to add tracks to the (end of the) tracklist and to reset the tracklist all together (empty it).
- Since:
- ExerciseSheet03
- Version:
- 1
- Author:
- Jonas Altrock (ew20b126@technikum-wien.at)
-
-
Constructor Summary
Constructors Constructor Description Concert()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddTrack(Track t)adds a track to the set listintduration()calculates the total duration (in seconds) of all tracks in the setlistprivate voidensureCapacity(int length)ensures sufficient storage for a specific number of tracks in the setlistTrack[]getSetList()gets the setlistintimpact()returns the impact of this eventintnrTracks()get the length of the playlist the length of the playlist is the number of entries in the setlist.voidresetSetList()removes all tracks from the setlistvoidsetSetList(Track[] tracks)sets the setListjava.lang.StringtoString()returns a String representation of this concert-
Methods inherited from class MusicLandscape.entities.Event
getArtist, getAttendees, getDate, getDescription, getVenue, setArtist, setAttendees, setDate, setDescription, setVenue
-
-
-
-
Field Detail
-
nextIdx
private int nextIdx
next free index
-
setList
private Track[] setList
array holding the tracks of the setlist
-
-
Method Detail
-
addTrack
public boolean addTrack(Track t)
adds a track to the set listTracks are added to the end of the list with the first track played at the concert being stored at the beginning of the list. This method returns whether the non-null track was successfully added to the setlist or not. This method does not accept/ignores null tracks.
- Parameters:
t- the track to add- Returns:
- true if the track was added, false otherwise
-
ensureCapacity
private void ensureCapacity(int length)
ensures sufficient storage for a specific number of tracks in the setlistIf the requested capacity can not be ensured before the call, this method increases storage thereby keeping all existing entries.
- Parameters:
length- the maximum number of tracks this concert must be able to keep in the setlist
-
getSetList
public Track[] getSetList()
gets the setlistThis method returns a defensive copy, meaning it returns a copy of the setlist, which contains (deep) copies of the tracks in the setlist. The returned array does not contain any null entries. If the setlist is empty an array of length 0 is returned.
- Returns:
- the setlist of this concert
-
setSetList
public void setSetList(Track[] tracks)
sets the setListThis method creates a defensive copy, meaning it sets the setlist of this concert to contain (deep copies of) all non-null tracks of the argument (and only those) thereby preserving the relative ordering of entries. Null entries in the argument are ignored and not part of the resulting setlist. A null argument is generally ignored.
- Parameters:
tracks- the tracks for the setlist
-
resetSetList
public void resetSetList()
removes all tracks from the setlist
-
nrTracks
public int nrTracks()
get the length of the playlist the length of the playlist is the number of entries in the setlist.- Returns:
- the number of tracks in the setlist
-
duration
public int duration()
calculates the total duration (in seconds) of all tracks in the setlistMore specifically the method returns an estimation (lower bound) since tracks with unknown duration are treated having duration 0.
- Returns:
- the total duration of the setlist in seconds
-
impact
public int impact()
returns the impact of this eventthe impact is an estimation of the number of people who took notice of this event. For a concert, the impact is calculated from the number of attendees and the length of the concert. The number of attendees is multiplied by the duration factor, which is initially 1 but increases by one for every started half hour the concert lasts. E.G: 400 people attending the concert. 75 minutes duration; duration factor=3 (two full half hours, plus one started half hour) impact therefore is 400*3.
-
toString
public java.lang.String toString()
returns a String representation of this concertthe string representation of a concert appends the following line to the string representation of a generic event (without quotes):
"number of tracks" tracks played, total duration "time".
time is displayed in the format hh:mm with leading zeros
-
-